<template>
  <div class="user">
    <el-dialog
      title="关联用户"
      :visible.sync="dialogTableVisible"
      @close="close"
      custom-class="custom-dialog-header"
      width="40%"
    >
      <el-form :model="formData">
        <el-form-item label="所属机构组织：" label-width="120px">
          <el-input
            placeholder="请输入"
            v-model="formData.institution"
          ></el-input>
        </el-form-item>
      </el-form>
      <h4 class="user">待关联用户</h4>
      <p class="chooseuser">用户选择:</p>
      <div class="contentTtable">
        <el-table
          ref="dataTable"
          height="135"
          :key="tableKey"
          v-loading="listLoading"
          :data="list1"
          :header-cell-style="{
            background: '#EAF1FF',
            'text-align': 'center',
            color: '#000',
          }"
          :cell-style="{ 'text-align': 'center' }"
          fit
          highlight-current-row
          @selection-change="handleSelectionChange"
          style="width: 100%"
          :border="false"
          select-on-click-header
          
        >
       

          <el-table-column  prop="isSelected" align="center" width="68" type="selection">
          
          </el-table-column>
          <el-table-column label="账号" width="248" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.number }}</span>
            </template>
          </el-table-column>
          <el-table-column label="姓名" width="auto" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.name }}</span>
            </template>
          </el-table-column>
        </el-table>
        <section>
             <h4 class="choosed">已关联用户</h4>
              <el-button size="small">删除</el-button>
        </section>
<!-- ------bottomForm -->
          <el-table
          
          ref="dataTable"
          height="265"
          :key="tableKey1"
          v-loading="listLoading"
          :data="list"
          :header-cell-style="{
            background: '#EAF1FF',
            'text-align': 'center',
            color: '#000',
          }"
          :cell-style="{ 'text-align': 'center' }"
          fit
          highlight-current-row
          @selection-change="handleSelectionChange()"
          style="width: 100%"
          :border="false"
          select-on-click-header
         
        >
       

          <el-table-column  prop="isSelected" align="center" width="68" type="selection">
          
          </el-table-column>
          <el-table-column label="组织机构" width="172" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.id }}</span>
            </template>
          </el-table-column>
          <el-table-column label="账号" width="172" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.pageviews }}</span>
            </template>
          </el-table-column>
          <el-table-column label="姓名" width="auto" align="center">
            <template slot-scope="{ row }">
              <span>{{ row.author }}</span>
            </template>
          </el-table-column>
        </el-table>
     
      </div>
       <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="listQuery.page"
          :limit.sync="listQuery.limit"
          @pagination="getList"
        />
      
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogTableVisible = false"
          >确 定</el-button
        >
        <el-button @click="dialogTableVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination"; 
import { fetchList, fetchPv } from "@/api/article";
export default {
    components: { Pagination },
  props: {
    //  dialogTableVisible: Boolean, // 接收父组件传递的 prop
    id: Number,
  },

  data() {
    return {
      tableKey: 0,
      tableKey1:1,
      list1: [
        {id:1, number: 1111, name: "aaaa", isSelected: false },
        {id:2, number: 2222, name: "bbbb", isSelected: false },
      ],
      // list2: [
      //   {id:1, institution:"hxb" , name: "李四",number:'1234', isSelected: false },
      //   {id:2, institution: "hxb", name: "张三",number:'12344321', isSelected: false },
      //   {id:3, institution: "hxb", name: "张三",number:'12344321', isSelected: false },
      //   {id:4, institution: "hxb", name: "张三",number:'12344321', isSelected: false },
      //   {id:5, institution: "hxb", name: "张三",number:'12344321', isSelected: false },
      // ],
        list: null,
      total: 0,
        listQuery: {
        page: 1,
        limit: 20,

        importance: undefined,
        title: undefined,
        type: undefined,
        sort: "+id",
      },
      checked: true,
     listLoading: true,
      dialogTableVisible: false,
      formData: {
        institution: "",
      },
       downloadLoading: false,
        
    };
  },
    created() {
    this.getList();
    // console.log(this.temp);
  }, 

  methods: {
    close() {
      this.dialogTableVisible = false;
    },
      getList() {
      this.listLoading = true;
      fetchList(this.listQuery).then((response) => {
        console.log(response);
        this.list = response.data.items;
        this.total = response.data.total;

        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false;
        }, 1.5 * 1000);
      });
    },
    handleSelectionChange(selection){
console.log(selection);
    }
  
  

  },
};
</script>

<style lang='scss'>
.user {
  .custom-dialog-header .el-dialog__header {
    background-color: #5084fb; /* 自定义背景色 */
    /* 其他样式属性 */
    color: #ffffff;
  }
  .el-dialog__title,
  .el-dialog__headerbtn i {
    color: white;
  }
  .el-dialog__footer {
    text-align: center;
  }
  .chooseuser{
    margin: 10px 0;
  }
 .chooseuser,.user{
    margin-left: 10px;
 }
  .contentTtable{
    
    section{
      display: flex;
      justify-content: space-between;
      margin-top: 10px;
      margin-left: 10px;
      margin-bottom: 10px;
     .choosed{
      display: flex;
      justify-content: center;
      align-items: center;
     }
    }
  }
}
</style>